package com.yuejian.neusoft.yuejian_24.adapter;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yuejian.neusoft.yuejian_24.R;
import com.yuejian.neusoft.yuejian_24.javaBean.Question;

import java.util.List;


/**
 * Created by q4549 on 2017/10/21.
 */
public class QuestionListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private SharedPreferences sp;
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public QuestionListAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.question_cardview,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Question entity = (Question) mDataList.get(position);
        if (null == entity){
            return;
        }else {
            final ViewHolder viewHolder = (ViewHolder) holder;
            viewHolder.qu_name.setText(entity.getQu_people()+"：");
            viewHolder.an_name.setText(sp.getString("master_name","")+"：");
            viewHolder.qu_content.setText(entity.getQu_content());
            viewHolder.an_content.setText(entity.getAn_content());
            viewHolder.qu_time.setText(entity.getQu_time());
            viewHolder.an_time.setText(entity.getAn_time());

        }
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView qu_name,an_name,qu_content,an_content,qu_time,an_time;
        LinearLayout qt_container;

        public ViewHolder(View itemView) {
            super(itemView);
            qu_name = (TextView) itemView.findViewById(R.id.qu_name);
            an_name = (TextView) itemView.findViewById(R.id.an_name);
            qu_content = (TextView) itemView.findViewById(R.id.qu_content);
            an_content = (TextView) itemView.findViewById(R.id.an_content);
            qu_time = (TextView)itemView.findViewById(R.id.qu_time);
            an_time = (TextView)itemView.findViewById(R.id.an_time);
            qt_container= (LinearLayout)itemView.findViewById(R.id.question_container);
            sp = mContext.getSharedPreferences("userinfo", Context.MODE_PRIVATE);
        }
    }
}
